<?php
    
    include_once '../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $tc = $_REQUEST['tc'];
    
    if($tc == 1){
    $quirofano = "select sqx.proid,paciente,qxfingres,qxfentsa,qxfcomcx,qxftermcx,qxfingrerec,
                  qxfalta,qxfsalida,usu_oidingres,usu_oidents,usu_oidco,usu_oidtr,
                  usu_oidinrec,usu_oidalta,usu_oidsali,ltrim(rtrim(PACPRINOM+' '+PACSEGNOM+' '+PACPRIAPE+' '+PACSEGAPE))as nom_paciente,
                  qxestado,recu.recespeciali as especialidadH,recua.recespeciali as especialidadA,recu.recirujano as hospi,
                  recua.recirujano as ambu,ciruH.USUDESCRI as cirujanoH,ciruA.USUDESCRI as cirujanoA,qxestado,recu.reccirujano2 as cirujano2H,recua.reccirujano2 as cirujano2A
                  from setquirofano as sqx left outer join pcrecuperacion as recu on sqx.proid = recu.proid
                  left outer join pcrecuperacionA as recua on sqx.proid = recua.proid
                  left outer join ".$con->getReal()."..GENUSUARIO as ciruH on recu.recirujano = ciruH.USUNOMBRE
                  left outer join ".$con->getReal()."..GENUSUARIO as ciruA on recua.recirujano = ciruA.USUNOMBRE
                  left outer join ".$con->getReal()."..GENPACIEN on sqx.paciente =  GENPACIEN.PACNUMDOC
                  where usu_oidsali = 0 and paciente <> '' and ltrim(rtrim(PACPRINOM+' '+PACSEGNOM+' '+PACPRIAPE+' '+PACSEGAPE)) <>''";
    $res = $con->query($quirofano);
    
    while ($res2 = mssql_fetch_array($res)){
        $lista[] = array_map(utf8_encode,$res2);
    }
    
     print_r(json_encode($lista));
    }
    else if($tc == 2){
         $gineco = "SELECT  P.OID,PACNUMDOC,ltrim(rtrim(PACPRINOM+' '+PACSEGNOM+' '+PACPRIAPE+' '+PACSEGAPE))as NOM_PAC,ate_conducta,
                    CASE WHEN ate_conducta = 'etp' THEN 'EN TRABAJO DE PARTO'
                    WHEN ate_conducta = 'espp' THEN 'EN SALA DE POST PARTO'
                    WHEN ate_conducta = 'adm' THEN 'EN ADMISIONES'
                    WHEN ate_conducta = 'hg' THEN 'HOSPITALIZADA EN GINECOOBSTETRICIA' 
                    WHEN ate_conducta = 'eqx' THEN 'EN QUIROFANO' 
                    WHEN ate_conducta = 'do' THEN 'EN OBSERVACION'  END AS CONDUCTA,
                    ate_diagEgreso,ate_fecha
                    FROM atenMaterna AS M
                    LEFT OUTER JOIN  ".$con->getReal()."..GENPACIEN as P on M.genPacien = P.OID
                    WHERE ate_conducta IN  ('etp','espp','adm','hg','eqx','do') AND ate_diagEgreso = 10
                    AND ate_fecha Between '11-14-2014 00:00:00.000' AND GETDATE()
                   order by NOM_PAC ASC";
    $res = $con->query($gineco);
    
    while ($res2 = mssql_fetch_array($res)){
        $lista[] = array_map(utf8_encode,$res2);
    }
    
     print_r(json_encode($lista));
    }
    $con->cerrarConexion();
    
?>
